<?php


namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Backend\BaseController;
use App\Services\Other\Interfaces\SearchRecordServiceInterface;
use App\Services\Business\Models\SearchKeywords;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;


class SearchController extends BaseController
{




    public function latest(Request $request)
    {

        $appId = Auth::user()->app_id;
        $keywords =  SearchKeywords::query()
            ->when($appId, function ($query) use ($appId) {
                return $query->whereUserId($appId);
            })
            ->orderByDesc('created_at')
            ->take(10)->get();
        return $this->successData(compact('keywords'));

    }

    public  function delete(Request $request){

        $appId = Auth::user()->app_id;
        $ids = $request->input('ids',[]);
        if (!$ids){
            return $this->error(__('参数错误'));
        }
        SearchKeywords::query()->where('user_id',$appId)->whereIn('id',$ids)->delete();
        return  $this->success(__('清除关键字成功'));


    }






}